using System;
using UnityEngine;
using UnityEngine.UI;

public class CoinGameManager : MonoBehaviour
{
    public static CoinGameManager Instance { get; private set; }
    
    private int score = 0;//得分
    private int totalCoins;//所有金币数量

    void Awake()
    {
        Instance       = this;
    }

    private void Start()
    {
        CoinEvent.ScoreChange(score);
        //获取金币数量
        totalCoins = GameObject.FindGameObjectsWithTag("Coin").Length;
        CoinEvent.CoinChange(totalCoins);
    }

    //收集金币、增加分数、碰到金币后销毁、更新分数
    public void CollectCoin(GameObject coin)
    {
        Destroy(coin);
        score = score+10;
        CoinEvent.ScoreChange(score);
        --totalCoins;
        CoinEvent.CoinChange(totalCoins);
    }
    
  
}